local extension=Package("jbsheg")
extension.extensionName="jbs2"
extension.game_modes_whitelist = { 'nos_heg_mode', 'new_heg_mode' ,"jbsnew_heg_mode"}
local U = require "packages/utility/utility"
local T = require "packages/jbs/record/Theorem"
local H = require "packages/hegemony/util"
Fk:loadTranslationTable{
    ["jbsheg"]="私服国战-官",
    
}

local heg = Fk.game_modes["new_heg_mode"]
table.insertTable(heg.whitelist, {"jbsheg"})

local sunli = General(extension, "jbsheg__sunli", "wei", 4)
local caomao=T.creategenandtanslatene({extension,"jbsheg__caomao","wei",4},{"曹髦","霸业的终耀"})
caomao.mainMaxHpAdjustedValue = -1
T.skilltranslate("jbsheg_qianlong",{"潜龙",[[你受到伤害后，你可以展示牌堆顶部的三张牌，获得其中至多X张牌（X为为你的同势力角色数，且至多为2）,
然后将剩余的牌置于牌堆底。]]})

T.skilltranslate("jbsheg_fensi",{"忿肆",[[主将技，你计算体力上限时减少1个单独的阴阳鱼；
出牌阶段限一次，你可以弃置一张牌，对一名同势力角色造成一点伤害，若该角色不为你，你失去一点体力。]]})
T.tablestranslate(
  {"#jbsheg_fensi","#nitian-ask"},
  {"你可以弃置一张牌，对一名同势力角色造成一点伤害","你可以少摸一张牌，与一名其他角色交换副将。"}
)
local qianlong = fk.CreateTriggerSkill{
  name = "jbsheg_qianlong",
  anim_type = "masochism",
  events = {fk.Damaged},
  relate_to_place = "m",

  can_trigger = function(self, event, target, player, data)
    return target == player and target:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3)
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonJustMove,
      skillName = self.name,
      proposer = player.id,
    })
    local kingdomMapper = H.getKingdomPlayersNum(room)
    local n = math.min(kingdomMapper[H.getKingdom(player)],2)
    local result = room:askForGuanxing(player, cards, {0, 3}, {0, n}, self.name, true, {"Bottom", "toObtain"})
    if #result.bottom > 0 then
      room:moveCardTo(result.bottom, Player.Hand, player, fk.ReasonJustMove, self.name, "", true, player.id)
    end
    if #result.top > 0 then
      room:moveCards{
        ids = result.top,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonJustMove,
        skillName = self.name,
        drawPilePosition = -1,
        moveVisible = true,
      }
    end
  end,
}

local fensi=fk.CreateActiveSkill{
  name = "jbsheg_fensi",
  anim_type = "offensive",
  target_num = 1,
  card_num = 1,

  prompt ="#jbsheg_fensi",

  can_use = function(self, player)
    return not player:isKongcheng()  and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,

  target_filter = function(self, to_select, selected, selected_cards)
    if #selected == 0 and H.compareKingdomWith(Self, Fk:currentRoom():getPlayerById( to_select)) then
      return true
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:throwCard(effect.cards, self.name, player)
    room:damage{
      from = player,
      to = target,
      damage = 1,
      skillName = self.name,
    }
    if target~=player then
      room:loseHp(player,1,self.name)
    end
  end,
}

local kangli = fk.CreateTriggerSkill{
  name = "jbsheg_kangli",
  anim_type = "masochism",
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player then

     return player:hasSkill(self) and player:usedSkillTimes(self.name)<1
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
      local ids = table.filter(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@kangli-inhand") > 0 end)
      room:throwCard(ids, self.name, player, player)
    else
    local kingdomMapper = H.getKingdomPlayersNum(room)
        local n = kingdomMapper[H.getKingdom(player)]
    player:drawCards(n, self.name, nil, "@@kangli-inhand")
    end
  end,
  refresh_events = { fk.DamageCaused },
  can_refresh = function(self, event, target, player, data)
    return target==player and table.find(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@kangli-inhand") > 0 end)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
        local ids = table.filter(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@kangli-inhand") > 0 end)
        room:throwCard(ids, self.name, player, player)
    end
  end,
}
caomao:addSkill(qianlong)
caomao:addSkill(fensi)
sunli:addSkill(kangli)
Fk:loadTranslationTable{
  ["jbsheg__sunli"] = "孙礼",
  ["jbsheg__simayi"] = "司马懿",
  ["designer:jbsheg__sunli"] = "老酒馆的猫",
  ["jbsheg_kangli"] = "伉厉",
  [":jbsheg_kangli"] = "每回合限一次。当你造成或受到伤害后，你摸X张牌，然后你下次造成伤害时弃置这些牌。（X为与你势力相同的角色数）",
}
local simayan=T.creategenandtanslatene({extension,"jbsheg__simayan","jin",3,3},{"司马炎","狼睨江左"})
local simayi=T.creategenandtanslatene({extension,"jbsheg__simayi","jin",3,3},{"司马懿","晋国之祖"})
local simashi=T.creategenandtanslatene({extension,"jbsheg__simashi","jin",3,3},{"司马师","晋景王"})
local simazhao=T.creategenandtanslatene({extension,"jbsheg__simazhao","jin",3,3},{"司马昭","晋文帝"})
local zhanghua=T.creategenandtanslatene({extension,"jbsheg__zhanghua","jin",3,3},{"张华","清骨博志"})
local duyu=T.creategenandtanslatene({extension,"jbsheg__duyu","jin",4,4},{"杜预","老登"})
local zhanghuyuechen=T.creategenandtanslatene({extension,"jbsheg__zhanghuyuechen","jin",4,4},{"张虎乐綝","不辱门庭"})
local wenyang=T.creategenandtanslatene({extension,"jbsheg__wenyang","jin",5},{"文鸯","声震秦凉"})
local wangyuanji=T.creategenandtanslatene({extension,"jbsheg__wangyuanji","jin",3,3,General.Female},{"王元姬","想看无惨"})
local zhangchunhua=T.creategenandtanslatene({extension,"jbsheg__zhangchunhua","jin",3,3,General.Female},{"张春华","想看无惨"})
local xiahouhui=T.creategenandtanslatene({extension,"jbsheg__xiahouhui","jin",3,3,General.Female},{"夏侯徽","想看无惨"})
local yanghuiyu=T.creategenandtanslatene({extension,"jbsheg__yanghuiyu","jin",3,3,General.Female},{"羊徽瑜","想看无惨"})
local zhongyan=T.creategenandtanslatene({extension,"jbsheg__zhongyan","jin",3,3,General.Female},{"钟琰","聪慧弘雅"})
local wangjun=T.creategenandtanslatene({extension,"jbsheg__wangjun","jin",4,4},{"王濬","艘舸成陆"})
local yanghu=T.creategenandtanslatene({extension,"jbsheg__yanghu","jin",4,4},{"羊祜","德亘如岳"})
local wangxiang=T.creategenandtanslatene({extension,"jbsheg__wangxiang","jin",3},{"王祥","沂川跃鲤"})

zhangchunhua:addSkill("ol__huishi")
zhangchunhua:addSkill("qingleng")
simayi:addSkill("yingshis")
simayi:addSkill("xiongzhi")
simashi:addSkill("yimie")
simashi:addSkill("tairan")
simazhao:addSkill("choufa")
simazhao:addSkill("zhaoran")
wangyuanji:addSkill("yanxi")
xiahouhui:addSkill("yishi")
xiahouhui:addSkill("shidu")
duyu:addSkill("sanchen")
yanghuiyu:addSkill("ciwei")
simayi:addCompanions({"jbsheg__zhangchunhua"})
simazhao:addCompanions({"jbsheg__wangyuanji"})
simashi:addCompanions({"jbsheg__xiahouhui"})
yanghuiyu:addCompanions({"jbsheg__simashi"})
zhanghua:addSkill("zx_heg__fuli")
zhanghua:addSkill("zx_heg__fengwu")
--wangxiang:addSkill("bingxin")
zhongyan:addSkill("yifa")
local caiyuan=fk.CreateTriggerSkill{
  name = "jbsheg_caiyuan",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return H.compareKingdomWith(player,target)  and player:hasSkill(self) and target.phase == Player.Finish
    and  not (target:isWounded() and player:isWounded())
  end,
  on_cost = function(self, event, target, player, data)
    local room=player.room
    local tos = room:askForChoosePlayers(player, {player.id,target.id}, 1, 1, "#jbsheg_caiyuan", self.name)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room=player.room
    local to = self.cost_data
    room:getPlayerById(to):drawCards(1 , self.name)
  end,
}

T.skilltranslate("jbsheg_caiyuan",{"才媛",[[与你势力相同的角色结束阶段，若你或其未受伤，你可以令你或其摸一张牌。]]})
yanghuiyu:addSkill(caiyuan)

T.skilltranslate("jbsheg_lvli",{"膂力",[[每回合限一次，当你造成伤害后，你可以选择一项：1.摸牌至体力值；2.弃置所有手牌，你回复体力至与你弃牌数量相同。]]})
--：限定技，一名角色的回合结束时，若你或其没有手牌，你可以获得一个额外的回合。 
T.skilltranslate("jbsheg_duoqi",{"夺气",[[限定技，一名角色的回合结束时，若你或其没有手牌，你可以获得一个额外的回合。]]})

local lvli = fk.CreateTriggerSkill{
  name = "jbsheg_lvli",
  anim_type = "drawcard",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self)  then
      if event == fk.Damage then
        return player:usedSkillTimes(self.name) < 1
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room=player.room
    local choices={"jbslvli-draw","jbslvli-recover","Cancel"}
    local choice = room:askForChoice(player, choices,self.name,"#jbsheg_jbsheg_lvli")
    if choice ~= "Cancel" then
      self.cost_data = choice
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local ch=self.cost_data
    if ch=="jbslvli-draw" then
      local n = player:getHandcardNum() - player.hp
      if n < 0 then
        player:drawCards(-n, self.name)
      end
    elseif ch=="jbslvli-recover" then
      local n=player:getHandcardNum()
      player:throwAllCards("h")
      local x=n-player.hp
      if x>0 then
        player.room:recover{
          who = player,
          num = math.min(x, player:getLostHp()),
          recoverBy = player,
          skillName = self.name
        }
      end
    end
  end
}

local duoqi=fk.CreateTriggerSkill{
  name = "jbsheg_duoqi",
  anim_type = "offensive",
  prompt="#jbsheg_duoqi",
  frequency = Skill.Limited,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:usedSkillTimes(self.name,Player.HistoryGame) < 1  and player:hasSkill(self) 
    and  player:getHandcardNum()==0
  end,
  on_use = function(self, event, target, player, data)
    player:gainAnExtraTurn(true)
  end,
}

wenyang:addSkill(lvli)
wenyang:addSkill(duoqi)

T.skilltranslate("jbsheg_xijue",{"袭爵",[[当你首次明置该武将牌后，你获得4个“爵”标记；回合结束时，若你本回合造成的伤害不少于2，
你获得1个“爵”标记。你可以移去1个“爵”标记发动〖突袭〗或〖骁果〗。]]})
T.skilltranslate("jbsheg_keqing",{"克清",[[当你使用牌结算后，你可以横置所有受到此牌伤害的角色。
若仅有一名角色受到伤害，则本回合此技能失效，且其下回合每次使用牌时须弃置一张手牌。
]]})

--顺流：当你造成属性伤害后，你可以依次弃置所有横置的角色各一张牌。 作者：紫髯的小乔 https://www.bilibili.com/read/cv27539938/ 出处：bilibili

T.skilltranslate("jbsheg_shunliu",{"顺流",[[当你造成属性伤害后，你可以依次弃置所有横置的角色各一张牌。]]})
T.skilltranslate("jbsheg_quanbian",{"权变",[[当你于出牌阶段内第一次使用每种花色的手牌时，你可以令你此阶段不能再使用此花色的手牌，然后卜算X并摸一张牌。(X为你的体力上限)
]]})
T.skilltranslate("jbsheg_rouke",{"柔克",[[与你势力相同的角色于一回合内使用第一张牌时，若此牌为【杀】，其可以改为冰【杀】。 ]]})

local jbsheg_xijue = fk.CreateTriggerSkill{
  name = "jbsheg_xijue",
  anim_type = "offensive",
  events = {fk.GeneralRevealed, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.GeneralRevealed then
          local is=false
          for _, v in pairs(data) do
            if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then is=true end
          end
        if is then
          self.cost_data = 4
          return true
        end
      else
        if target == player then
          local room = player.room
          local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
          if turn_event == nil then return false end
          local n = 0
          room.logic:getActualDamageEvents(1, function(e)
            local damage = e.data[1]
            if damage.from == player then
              n = n + damage.damage
            end
          end, nil, turn_event.id)
          if n > 1 then
            self.cost_data = 1
            return true
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@zhanghuyuechen_jue", self.cost_data)
  end,

  refresh_events = {fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    return player == target and data == self
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@zhanghuyuechen_jue", 0)
  end,
}
local xijue_tuxi = fk.CreateTriggerSkill{
  name = "#jbsheg_xijue_tuxi",
  anim_type = "control",
  main_skill = jbsheg_xijue,
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return (target == player and player:hasSkill(jbsheg_xijue) and data.n > 0 and player:getMark("@zhanghuyuechen_jue") > 0 and
      not table.every(player.room:getOtherPlayers(player, false), function (p) return p:isKongcheng() end))
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
      return not p:isKongcheng() end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, 2, "#xijue_tuxi-invoke", "tuxi", true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@zhanghuyuechen_jue", 1)
    player:broadcastSkillInvoke("tuxi")
    local targets = table.simpleClone(self.cost_data)
    room:sortPlayersByAction(targets)
    for _, id in ipairs(targets) do
      if player.dead then break end
      local p = room:getPlayerById(id)
      if not (p.dead or p:isKongcheng()) then
        local c = room:askForCardChosen(player, p, "h", "tuxi")
        room:obtainCard(player.id, c, false, fk.ReasonPrey)
      end
    end
    return true
  end,
}
local xijue_xiaoguo = fk.CreateTriggerSkill{
  name = "#jbsheg_xijue_xiaoguo",
  anim_type = "offensive",
  main_skill = jbsheg_xijue,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and not target.dead and player:hasSkill(jbsheg_xijue) and not player:isKongcheng() and
    player:getMark("@zhanghuyuechen_jue") > 0 and target.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, false, "xiaoguo", true, ".|.|.|.|.|basic", "#xijue_xiaoguo-invoke::"..target.id, true)
    if #card > 0 then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@zhanghuyuechen_jue", 1)
    player:broadcastSkillInvoke("xiaoguo")
    room:doIndicate(player.id, {target.id})
    room:throwCard(self.cost_data, "xiaoguo", player, player)
    if target.dead then return false end
    if #room:askForDiscard(target, 1, 1, true, "xiaoguo", true, ".|.|.|.|.|equip", "#xiaoguo-discard:"..player.id) > 0 then
      player:drawCards(1, "xiaoguo")
    else
      room:damage{
        from = player,
        to = target,
        damage = 1,
        skillName = "xiaoguo",
      }
    end
  end,
}

jbsheg_xijue:addRelatedSkill(xijue_tuxi)
jbsheg_xijue:addRelatedSkill(xijue_xiaoguo)
local keqing = fk.CreateTriggerSkill{
  name = "jbsheg_keqing",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)  and data.damageDealt and 
    table.find(player.room.alive_players, function (p) return data.damageDealt[p.id] and data.damageDealt[p.id]>0 end) and
    player:getMark("keqing_invalid-turn")==0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --横置
    local targets = table.filter(room.alive_players, function (p) return data.damageDealt[p.id] and data.damageDealt[p.id]>0 end)
    for _, p in ipairs(targets) do
      if not p.dead then
        p:setChainState(true)
      end
    end
    if #targets==1 then
      room:setPlayerMark(player, "keqing_invalid-turn", 1)
      room:setPlayerMark(targets[1], "keqing_debuff", 1)
      
    end
  end,
  refresh_events = { fk.TurnEnd,fk.CardUsing },
  can_refresh = function(self, event, target, player, data)


    return target==player and target:getMark("keqing_debuff")>0
  
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      room:setPlayerMark(target, "keqing_debuff", 0)
    else 
      if not player:isKongcheng() then
        room:askForDiscard(player, 1, 1, false, self.name, false,nil, "#jbsheg_keqing")
      end
    end
  end,
}

local shunliu= fk.CreateTriggerSkill {
  name = "jbsheg_shunliu",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  mute = true,
  events = {  fk.Damaged },
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.Damaged then
            return data.damageType ~= fk.NormalDamage
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p) return p.chained end)
    if #targets==0 then return false end
    for _, p in ipairs(targets) do
      if not p.dead and not p:isKongcheng() then
        local cards = room:askForCardsChosen(player,p, 1, 1, "hej", self.name)
        if #cards > 0 then
          room:throwCard(cards, self.name, p, player)
        end
      end
    end
  end,
}

local quanbian = fk.CreateTriggerSkill{
  name = "jbsheg_quanbian",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Play and data.card.suit ~= Card.NoSuit and
      U.IsUsingHandcard(player, data) then
      local card_suit = data.card.suit
      local room = player.room
      local logic = room.logic
      local current_event = logic:getCurrentEvent()
      local mark_name = "quanbian_" .. data.card:getSuitString() .. "-phase"
      local mark = player:getMark(mark_name)
      if mark == 0 then
        logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
          local use = e.data[1]
          if use.from == player.id and use.card.suit == card_suit then
            mark = e.id
            room:setPlayerMark(player, mark_name, mark)
            return true
          end
          return false
        end, Player.HistoryPhase)
      end
      return mark == current_event.id
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local mark = player:getMark("@quanbian-phase")
    if mark == 0 then mark = {} end
    table.insert(mark, data.card:getSuitString(true))
    player.room:setPlayerMark(player, "@quanbian-phase", mark)
    self:doCost(event, target, player, data)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suits = {"spade", "club", "heart", "diamond"}
    table.remove(suits, data.card.suit)
    room:askForGuanxing(player, room:getNCards(player.maxHp))
    player:drawCards(1, self.name)
  end,

}

local quanbian_prohibit = fk.CreateProhibitSkill{
  name = "#jbsheg__quanbian_prohibit",
  prohibit_use = function(self, player, card)
    return player:getMark("@quanbian-phase") ~= 0 and 
    table.contains(player:getMark("@quanbian-phase"), card:getSuitString(true))
  end,
}

quanbian:addRelatedSkill(quanbian_prohibit)

local rouke = fk.CreateTriggerSkill{
  name = "jbsheg_rouke",
  anim_type = "support",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and H.compareKingdomWith(player,target) then
      local use_e = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        return e.data[1].from == target.id
      end, Player.HistoryTurn)
      return #use_e > 0 and use_e[1].data[1] == data and data.card.trueName == "slash" and #TargetGroup:getRealTargets(data.tos) ~= 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(target, self.name, ".", "#jbsheg_rouke-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local names = {"ice__slash"}
    local from = room:getPlayerById(data.from) 
    local to = from 
    --if U.canUseCardTo(room, from, to, Fk:cloneCard("ice__slash")) then table.insert(names, "ice__slash") end
    if #names == 0 then return true end
    local new_data = table.simpleClone(data)
    local name = table.random(names)
    local card = Fk:cloneCard(name)
    card:addSubcards(data.card:isVirtual() and data.card.subcards or {data.card.id})
    card.skillName = self.name
    new_data.card = card
    room:sendLog{
      type = "#roukechange",
      from = data.from,
      arg = self.name,
      arg2 = data.card:toLogString(),
      arg3 = name,
    }
    data.card=new_data.card
    --[[
    room:delay(700)
    playCardEmotionAndSound(room, from, card)
    room:doIndicate(from.id, {to.id})
    room:doCardUseEffect(new_data)
    return true
    --]]

  end,
}

simayi:addSkill(quanbian)



yanghu:addSkill(rouke)
yanghu:addSkill(shunliu)

wangjun:addSkill(keqing)
wangjun:addCompanions({"jbsheg__yanghu"})

zhanghuyuechen:addSkill(jbsheg_xijue)
zhanghuyuechen:addRelatedSkill("tuxi")
zhanghuyuechen:addRelatedSkill("xiaoguo")
Fk:loadTranslationTable{
  ["#jbsheg_caiyuan"]="你可以令你或队友摸一张牌",
  ["#jbsheg_jbsheg_lvli"]="膂力:选择一项：",
  ["#jbsheg_duoqi"]="夺气:你可以获得一个额外的回合",
  ["jbslvli-draw"]="摸牌至体力值",
  ["jbslvli-recover"]="弃置所有手牌，你回复体力至与你弃牌数量相同",
  ["#jbsheg_keqing"]="克清：弃置一张手牌",
  ["#jbsheg_rouke-invoke"]="柔克:是否将此【杀】改为冰【杀】？",
  ["#roukechange"]= "由于“%arg”的效果，%from 使用的 %arg2 效果改为 %arg3",
  ["#jbsheg_xijue_tuxi"]="突袭",
  ["#jbsheg_xijue_xiaoguo"]="骁果",
  ["#jbsheg__quanbian_prohibit"]="权变",
}

-----------8.11
--
T.skilltranslate("jbsheg_bolan",{"博览",[[每名角色的出牌阶段开始时，其可以展示武将牌堆
的一张牌，根据此武将牌的势力于此阶段获得以下
技能，然后若其体力值大于你，其失去1点体力：<br>
魏~“奇策”；蜀~“挑衅”；吴~“制衡”；<br>
群~“除疠”；晋~“三陈”]]})
local bolan = fk.CreateTriggerSkill{
  name = "jbsheg_bolan",
  anim_type = "special",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(target, self.name, ".", "#jbsheg_bolan-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local list={["shu"]="tiaoxin",["wei"]="ld__qice",["wu"]="hs__zhiheng",["qun"]="hs__chuli",["jin"]="sanchen"}
    if #room.general_pile == 0 then return false end
   

    local x=table.random(room.general_pile)
    room:doBroadcastNotify("ShowToast", "抽到了武将"..Fk:translate(x))
    local g=Fk.generals[x]
    local v=g.kingdom or "shu"
    room:handleAddLoseSkills(target, list[v])
    room.logic:getCurrentEvent():findParent(GameEvent.Phase):addCleaner(function()
    room:handleAddLoseSkills(target, "-"..list[v])
  end)
  if target.hp>player.hp then
    room:loseHp(target,1,self.name)
  end

  end,


}

zhongyan:addSkill(bolan)

T.tablestranslate(
  {"#jbsheg_bolan-invoke",},
  {"你可以弃置一张牌，其可以展示武将牌堆的一张牌，根据此武将牌的势力获得技能",}
)



local jiachong=T.creategenandtanslatene({extension,"jbsheg__jiachong","jin",3,3},{"贾充","兇兇踽行"})
jiachong:addCompanions({"jbsheg__simazhao"})

local jbsheg__chuitong = fk.CreateTriggerSkill{
  name = "jbsheg__chuitong",
  anim_type = "support",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EnterDying then
      return player:hasSkill(self) and target ~= player and #target:getCardIds("e") >0 and
      target:canMoveCardsInBoardTo(player, "e")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
     room:askForMoveCardInBoard(player, target, player, self.name, "e", target)
  end,
}

local jbsheg__xingtu = fk.CreateTriggerSkill{
  name ="jbsheg__xingtu",
  anim_type = "support",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
  local room = player.room
  --[[
  local cids = {}
  local dids = {}
    local events = room.logic:getEventsOfScope(GameEvent.MoveCards, 999, function(e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if room:getCardArea(info.cardId) == Card.DiscardPile then
               if Fk:getCardById(info.cardId, true):isCommonTrick() then
                 table.insertIfNeed(cids, info.cardId)
               end
               if Fk:getCardById(info.cardId, true).is_damage_card then
                 table.insertIfNeed(dids, info.cardId)
               end
            end
          end
        end
      end
    end, Player.HistoryTurn)
      self.cost_data = {cids,dids}
    return player:hasSkill(self) and (#cids == 1 or #dids == 1)
    --]]
    local logic = room.logic
    if not player:hasSkill(self) then return end
    local events=logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
        local use = e.data[1]
        if use.from and use.from==player.id and  
          table.find({"@fujia", "@kongchao", "@canqu", "@zhuzhan","@gujun"}, function(mark) return use.card:getMark(mark) ~= 0 end) then
          return true
        end
        return false
      end, Player.HistoryGame)

    return #events>0
  end,
  on_cost = function(self, event, target, player, data)
    local room=player.room
    local choices={}
    if table.find(room.alive_players,function (p) return p:isWounded() end) then table.insert(choices,"jbsxingtu-recover") end
      
    table.insertTable(choices,{"jbsxingtu-draw","Cancel"})
    local choice = room:askForChoice(player, choices,self.name,"#jbsheg_jbsheg_lvli")
    if choice ~= "Cancel" then
      self.cost_data = choice
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ch=self.cost_data
    if ch=="jbsxingtu-draw" then

        player:drawCards(1, self.name)

    elseif ch=="jbsxingtu-recover" then
      local targets=table.map(table.filter(room.alive_players,function (p) return p:isWounded() end),
      Util.IdMapper)
      if #targets==0 then return end
      local tar,cid=room:askForChooseCardAndPlayers(player, targets,1,1,".|.|.|.|.|equip","jbsxingtu-recover",true)
      local card=Fk:cloneCard("peach")
      card:addSubcard(cid)
      card.skillName = "jbsheg__xingtu"
      room:useCard {
        from = player.id,
        tos = table.map(tar, function(p) return { p } end),
        card = card,
      }
    end

  end,
}

simayan:addSkill(jbsheg__chuitong)
simayan:addSkill(jbsheg__xingtu)

simayan:addCompanions({"jbsheg__zhanghua"})

local jbsheg__beishi = fk.CreateTriggerSkill{
  name ="jbsheg__beishi",
  anim_type = "defensive",
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and U.isOnlyTarget(player, data, event) and  data.card and
    data.from ~= player.id 
  end,
  on_cost = function(self, event, target, player, data)
    local type=data.card:getTypeString()
    local c = player.room:askForDiscard(player, 1, 1, true, self.name, true,
     ".|.|.|.|.|"..type, "#n_chiyao-discard:::" .. data.card:toLogString(), true)

    if c[1] then
      
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
    if not data.card:isVirtual() then
 
        local use = {
        from = player.id,
        tos ={{data.from.id}},
        card = data.card,
      }
        use.card.skillName = self.name
        room:useCard(use)
        if not use.damageDealt then
          room:loseHp(player,1,self.name)
        end
    end
  
  end,
}

local jbsheg__tongfa = fk.CreateTriggerSkill{
  name = "jbsheg__tongfa",
  anim_type = "support",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then

      if event ==fk.CardUsing then
        return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and
          table.find({"@fujia", "@kongchao", "@canqu", "@zhuzhan","@gujun"}, function(mark) return data.card:getMark(mark) ~= 0 end)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.CardUsing then
      local card =  player.room:askForCard(target, 1, 1, true, self.name, true, ".",
      "#jbsheg__tongfa-give::"..player.id..":"..data.card:toLogString())
      if #card > 0 then
        self.cost_data = card[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      room:obtainCard(player,  self.cost_data, false, fk.ReasonPrey)
      data.extra_data = data.extra_data or {}
      data.extra_data.variation = true
    end
  end,
}

jiachong:addSkill(jbsheg__tongfa)
jiachong:addSkill(jbsheg__beishi)



T.skilltrstable{
  {"jbsheg__chuitong",{"垂统",[[其他角色进入濒死状态时，你可以将其装备区的一张牌移动至你装备区。]]}},
  {"jbsheg__xingtu",{"兴图",[[每回合结束时，若本回合有应变牌被使用过，你可以选择一项：1.将一张装备牌当【桃】对一名角色使用；2.摸一张牌。]]}},
  {"jbsheg__tongfa",{"通法",[[每回合限一次，有角色使用应变牌时，其可以交给你一张牌，然后你可以令其无视条件应变。]]}},
  {"jbsheg__beishi",{"悖弑",[[当你成为其他角色使用牌的唯一目标时，你可以弃置一张同类别牌并取消之，然后获得之；若此牌非转化，
  你对其使用之；若你未以此法使用牌对其造成伤害，你失去1点体力。]]}},
  {"jbsheg__bingxin",{"冰心",[[若你手牌的数量等于体力值且颜色相同，你可以摸一张牌视为使用一张与本轮以此法使用过的牌牌名不同的基本牌。]]}},
  
}

local bingxin = fk.CreateViewAsSkill{
  name = "jbsheg__bingxin",
  pattern = ".|.|.|.|.|basic|.",
  interaction = function()
    local all_names = U.getAllCardNames("b")
    local names = U.getViewAsCardNames(Self, "bingxin", all_names, {}, Self:getTableMark( "bingxin-round"))
    if #names > 0 then
      return UI.ComboBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player)
    local mark = player:getMark("bingxin-round")
    if mark == 0 then mark = {} end
    table.insert(mark, Fk:cloneCard(self.interaction.data).trueName)
    player.room:setPlayerMark(player, "bingxin-round", mark)
    player:drawCards(1, self.name)
  end,
  enabled_at_play = function(self, player)
    local cards = player.player_cards[Player.Hand]
    return #cards == player.hp and
      table.every(cards, function(id) return Fk:getCardById(id).color ==Fk:getCardById(cards[1]).color end)
  end,
  enabled_at_response = function(self, player, response)
    local cards = player.player_cards[Player.Hand]
    return not response and #cards == player.hp and
      table.every(cards, function(id) return Fk:getCardById(id).color ==Fk:getCardById(cards[1]).color end)
  end,
}

wangxiang:addSkill(bingxin)

T.easyliketrstable{
  {"jbsxingtu-recover","将一张装备牌当【桃】对一名角色使用"},
  {"jbsxingtu-draw","摸一张牌"},
  {"#jbsheg__beishi-discard","悖弑: 你可以弃置一张同类别牌令 %arg 无效并获得之"},
  {"#jbsheg__tongfa-give","你可以交给贾充一张牌，使该牌无视应变条件"}
}

return extension